package handin02;

/**
 * StringManipulator manipulates string.
 * 
 * @author Peter Tolstrup Aagesen
 * 
 * handin #2
 */

public class StringManipulator 
{
	//Variables for storing the number of times the methods are used
	private static int numToCamelCaseUsed = 0;
	private static int numOddOrEvenLengthUsed = 0;
	private static int numInitialsFromNameUsed = 0;	
	
	/**
	 * SubstringManipulator constructor
	 */
	public StringManipulator ()
	{
		
	}
	
	/**
	 * toCamelCase takes two String parameters and concatenates them into a camel cased String.
	 * 
	 * @param First String.
	 * @param Second String.
	 * @return Returns a camel cased String.
	 */	
	public static String toCamelCase(String s1, String s2)
	{
		//Add one to the variable storing the number of times this method has been used
		numToCamelCaseUsed += 1;
		
		//Create String for return result
		String camelCasedWord = "";
		
		//Convert words to lower case and store the result in variables
		String s1LowerCased = s1.toLowerCase();
		String s2LowerCased = s2.toLowerCase();
		
		//create new variable for the second string with first letter capitalized
		String s2FirstLetterCapitalized = s2LowerCased.substring(0,1).toUpperCase() +
										s2LowerCased.substring(1);
		
		//Concatenate the strings in return result
		camelCasedWord = s1LowerCased + s2FirstLetterCapitalized;
		
		//Return result
		return camelCasedWord;
	}
	
	/**
	 * oddOrEventLength test if the length of a String is odd or event.
	 * 
	 * @param s String to be tested.
	 * @return Returns 1 if the length of the String is odd otherwise 0.

	 */
	public static int oddOrEventLength(String s)
	{
		//Add one to the variable storing the number of times this method has been used
		numOddOrEvenLengthUsed ++;
		
		//Use modulus 2 on the length of the string to return 0 for even length and 1 odd length
		return s.length()%2;
	}
	
	/**
	 * initialsFromName creates capitalized initials from two Strings 
	 * 
	 * @param firstName First String
	 * @param secondName Second String
	 * @return Returns initials as capitals separated by a dot.
	 */	
	public static String initialsFromName(String firstName, String secondName)
	{
		//Add one to the variable storing the number of times this method has been used
		numInitialsFromNameUsed ++;
		
		//Create a String for the return result 
		String returnInitials = "";
		
		//Add the first letter of the first name as a capital to return result
		returnInitials += firstName.substring(0, 1).toUpperCase();
		
		//Add dot and space
		returnInitials += ". ";		

		//Add the first letter of the first name as a capital to return result
		returnInitials += secondName.substring(0, 1).toUpperCase();

		//Add final dot
		returnInitials += ".";	
		
		//Return result
		return returnInitials;		
	}
	
	/**
	 * generateUsageRepport prints a report the number of times the methods of the class has been used.
	 */
	public static void generateUsageReport()
	{
		System.out.println("Following classes been used:");
		//Print number of times toCamelCase has been used
		System.out.println("toCamelCase:" + numToCamelCaseUsed + " times");
		//Print number of times oddOrEvenLength has been used
		System.out.println("oddOrEvenLength:" + numOddOrEvenLengthUsed + " times");
		//Print number of times initialsFromName has been used
		System.out.println("initialsFromName:" + numInitialsFromNameUsed + " times");
	}
}
